package com.chengwei.ch.busdemo.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.chengwei.ch.busdemo.R;
import com.chengwei.ch.busdemo.base.BaseActivity;

@SuppressLint("Registered")
public class SignInResultActivity extends BaseActivity {

    private ConstraintLayout clSuccess, clFail;
    private Button btnAgain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_in_result);

        initView();
        initClickListener();
    }

    @SuppressLint("ResourceAsColor")
    private void initView() {
        clSuccess = findViewById(R.id.clSuccessSignInResult);
        clFail = findViewById(R.id.clFailSignInResult);
        btnAgain = findViewById(R.id.btnAgainSignInResult);
        showLayout("failure");
    }

    private void initClickListener() {
        btnAgain.setOnClickListener(this);
        clSuccess.setOnClickListener(this);
    }

    /**
     * 签到成功或失败弹框
     *
     * @param status = "success" -> 验票成功；status = "failure" -> 验票失败
     */
    private void showLayout(String status) {
        if (status.equals("success")) {
            clSuccess.setVisibility(View.VISIBLE);
            clFail.setVisibility(View.GONE);
        } else {
            clSuccess.setVisibility(View.GONE);
            clFail.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btnAgainSignInResult: {
                showLayout("success");
                break;
            }
            case R.id.clSuccessSignInResult: {
                Intent intent = new Intent();
                intent.setClass(SignInResultActivity.this, HomeActivity.class);
                startActivity(intent);
                break;
            }
            default:
                break;
        }
    }
}